<?php

class buildingimage extends CI_Model {

    function __construct() {
        parent::__construct();
    }
    
    function get_count() {
        return $this->db->count_all('building_image');
    }

    function add($building_id, $path = '', $decscription = '') {
        $data = array(
            'image_desc' => $decscription,
            'image_path' => $path,
            'building_id' => $building_id
        );

        $this->db->insert('building_image', $data);
        return $this->db->insert_id();
    }

    function delete($id) {
        $this->db->delete('building_image', array('image_id' => $id));
    }

    function get_building_images($building_id, $offset = 0, $limit = 0) {
        $this->db->select('image_id,image_desc,image_path,building_id');
        $this->db->from('building_image');
        $this->db->where('building_id', $building_id);
        if ($limit > 0){
            $this->db->limit($limit, $offset);
        }
        $query = $this->db->get();
        return $query->result();
    }

    function get_more_building_images($building_id, $offset, $limit) {
        $this->db->select('image_id,image_desc,image_path,building_id');
        $this->db->from('building_image');
        $this->db->where('building_id', $building_id);
        $this->db->limit($limit, $offset);
        $query = $this->db->get();
        return $query->result();
    }

    function get_first_building_image($building_id) {
        $building_id = intval($building_id);
        $sql = "SELECT * FROM `building_image` WHERE building_id = {$building_id} LIMIT 0,1";
        $query = $this->db->query($sql);
        if ($query->num_rows > 0) {
            return $query->result_array();
        }
        return "#";
    }

}

?>
